package com.agimatec.selenium.base;

import java.io.File;

public class ScreenshottingSelenium extends AjaxSelenium {
    private String group = "default";
    private int imageCounter = 0;
    private String folder;
    private final static String PATH = "target" + File.separator + "screenshots" + File.separator;

    public ScreenshottingSelenium(String serverHost, int serverPort,
                                  String browserStartCommand, String browserURL) {
        super(serverHost, serverPort, browserStartCommand, browserURL);
        folder = browserStartCommand.substring(1);
    }

    public void captureScreenshot() {
        File dir = new File(PATH + folder + File.separator + group);
        if(!dir.isDirectory()) {
            dir.mkdirs();
        }
        File file = new File(dir,imageCounter++ + ".png");
        super.captureScreenshot(file.getAbsolutePath());
    }

    public void setGroup(String group) {
        this.group = group;
        imageCounter = 0;
    }

    public void start() {
        super.start();
        windowMaximize();
    }

}
